/*
 * Copyright (c) Jiandong.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import hilog from '@ohos.hilog';
import Context from '@ohos.application.context';

import { ReactContext } from '../bridge/ReactContext';
import { PackagerConnectionSettings } from '../packagerConnection/PackagerConnectionSettings';
import { DeveloperSettings } from './DeveloperSettings';
/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

//package com.facebook.react.devsupport;
//
//import android.content.Context;
//import android.content.SharedPreferences;
//import android.preference.PreferenceManager;
//import com.facebook.react.common.annotations.VisibleForTesting;
//import com.facebook.react.common.build.ReactBuildConfig;
//import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
//import com.facebook.react.packagerconnection.PackagerConnectionSettings;

/**
 * Helper class for accessing developers settings that should not be accessed outside of the package
 * {@link com.facebook.react.devsupport}. For accessing some of the settings by external modules
 * this class implements an external interface {@link DeveloperSettings}.
 */
//@VisibleForTesting
export class DevInternalSettings
implements DeveloperSettings /*, SharedPreferences.OnSharedPreferenceChangeListener*/ {
  private static readonly TAG: string = "React DeveloperSettings"
  private static readonly PREFS_FPS_DEBUG_KEY = "fps_debug";
  private static readonly PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug";
  private static readonly PREFS_JS_MINIFY_DEBUG_KEY = "js_minify_debug";
  private static readonly PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug";
  private static readonly PREFS_INSPECTOR_DEBUG_KEY = "inspector_debug";
  private static readonly PREFS_HOT_MODULE_REPLACEMENT_KEY = "hot_module_replacement";
  private static readonly PREFS_REMOTE_JS_DEBUG_KEY = "remote_js_debug";
  private static readonly PREFS_START_SAMPLING_PROFILER_ON_INIT = "start_sampling_profiler_on_init";

//  private final SharedPreferences mPreferences;
//  private final Listener mListener;
  private readonly mPackagerConnectionSettings: PackagerConnectionSettings;

  public constructor(abilityContext: Context.AbilityContext /*,Listener listener*/) { //Context

    hilog.info(0x0000, DevInternalSettings.TAG, 'constructor');

//  mListener = listener;
//  mPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext);
//  mPreferences.registerOnSharedPreferenceChangeListener(this);
  this.mPackagerConnectionSettings = new PackagerConnectionSettings(abilityContext);
}

public getPackagerConnectionSettings(): PackagerConnectionSettings {
  return this.mPackagerConnectionSettings;
}

//@Override
//public boolean isFpsDebugEnabled() {
//  return mPreferences.getBoolean(PREFS_FPS_DEBUG_KEY, false);
//}
//
//public void setFpsDebugEnabled(boolean enabled) {
//  mPreferences.edit().putBoolean(PREFS_FPS_DEBUG_KEY, enabled).apply();
//}

//@Override
//public boolean isAnimationFpsDebugEnabled() {
//  return mPreferences.getBoolean(PREFS_ANIMATIONS_DEBUG_KEY, false);
//}

//@Override
public isJSDevModeEnabled(): boolean {
  return true;
//  return mPreferences.getBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, true);
}

public setJSDevModeEnabled(value: boolean): void {
//  mPreferences.edit().putBoolean(PREFS_JS_DEV_MODE_DEBUG_KEY, value).apply();
}
//
//@Override
//public boolean isJSMinifyEnabled() {
//  return mPreferences.getBoolean(PREFS_JS_MINIFY_DEBUG_KEY, false);
//}
//
//public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//  if (mListener != null) {
//    if (PREFS_FPS_DEBUG_KEY.equals(key)
//    || PREFS_JS_DEV_MODE_DEBUG_KEY.equals(key)
//    || PREFS_START_SAMPLING_PROFILER_ON_INIT.equals(key)
//    || PREFS_JS_MINIFY_DEBUG_KEY.equals(key)) {
//      mListener.onInternalSettingsChanged();
//    }
//  }
//}
//
//public boolean isHotModuleReplacementEnabled() {
//  return mPreferences.getBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, true);
//}
//
//public void setHotModuleReplacementEnabled(boolean enabled) {
//  mPreferences.edit().putBoolean(PREFS_HOT_MODULE_REPLACEMENT_KEY, enabled).apply();
//}
//
//public boolean isElementInspectorEnabled() {
//  return mPreferences.getBoolean(PREFS_INSPECTOR_DEBUG_KEY, false);
//}
//
//public void setElementInspectorEnabled(boolean enabled) {
//  mPreferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply();
//}

//@Override
public isDeviceDebugEnabled(): boolean {
    return true;
//  return ReactBuildConfig.IS_INTERNAL_BUILD && ReactBuildConfig.DEBUG;
}

//@Override
public isRemoteJSDebugEnabled(): boolean {
    return false;
//  return mPreferences.getBoolean(PREFS_REMOTE_JS_DEBUG_KEY, false);
}

//@Override
public setRemoteJSDebugEnabled( remoteJSDebugEnabled: boolean): void {

//  mPreferences.edit().putBoolean(PREFS_REMOTE_JS_DEBUG_KEY, remoteJSDebugEnabled).apply();
}

//@Override
//public boolean isStartSamplingProfilerOnInit() {
//  return mPreferences.getBoolean(PREFS_START_SAMPLING_PROFILER_ON_INIT, false);
//}
//
//@Override
//public void addMenuItem(String title) {
//  // Not supported.
//}
//
//public interface Listener {
//  void onInternalSettingsChanged();
//}
}
